/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('imagesearch', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model AddItemRequest {
  instanceName?: string(name='instanceName'),
}

model AddItemResponseBody = {
  code?: int32(name='Code'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model AddItemResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: AddItemResponseBody(name='body'),
}

async function addItem(request: AddItemRequest): AddItemResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return addItemWithOptions(request, headers, runtime);
}

async function addItemWithOptions(request: AddItemRequest, headers: map[string]string, runtime: Util.RuntimeOptions): AddItemResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.instanceName)) {
    query['instanceName'] = request.instanceName;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'AddItem',
    version = '2018-03-19',
    protocol = 'HTTPS',
    pathname = `/item/add`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model DeleteItemRequest {
  instanceName?: string(name='instanceName'),
}

model DeleteItemResponseBody = {
  code?: int32(name='Code'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model DeleteItemResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DeleteItemResponseBody(name='body'),
}

async function deleteItem(request: DeleteItemRequest): DeleteItemResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return deleteItemWithOptions(request, headers, runtime);
}

async function deleteItemWithOptions(request: DeleteItemRequest, headers: map[string]string, runtime: Util.RuntimeOptions): DeleteItemResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.instanceName)) {
    query['instanceName'] = request.instanceName;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DeleteItem',
    version = '2018-03-19',
    protocol = 'HTTPS',
    pathname = `/item/delete`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model SearchItemRequest {
  instanceName?: string(name='instanceName'),
}

model SearchItemResponseBody = {
  auctions?: {
    auction?: [ 
    {
      catId?: string(name='CatId'),
      custContent?: string(name='CustContent'),
      itemId?: string(name='ItemId'),
      picName?: string(name='PicName'),
      sortExprValues?: string(name='SortExprValues'),
    }
  ](name='Auction')
  }(name='Auctions'),
  code?: int32(name='Code'),
  head?: {
    docsFound?: int32(name='DocsFound'),
    docsReturn?: int32(name='DocsReturn'),
    searchTime?: int32(name='SearchTime'),
  }(name='Head'),
  message?: string(name='Message'),
  picInfo?: {
    allCategory?: {
      category?: [ 
      {
        id?: string(name='Id'),
        name?: string(name='Name'),
      }
    ](name='Category')
    }(name='AllCategory'),
    category?: string(name='Category'),
    region?: string(name='Region'),
  }(name='PicInfo'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model SearchItemResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: SearchItemResponseBody(name='body'),
}

async function searchItem(request: SearchItemRequest): SearchItemResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return searchItemWithOptions(request, headers, runtime);
}

async function searchItemWithOptions(request: SearchItemRequest, headers: map[string]string, runtime: Util.RuntimeOptions): SearchItemResponse {
  Util.validateModel(request);
  var query : map[string]any = {};
  if (!Util.isUnset(request.instanceName)) {
    query['instanceName'] = request.instanceName;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SearchItem',
    version = '2018-03-19',
    protocol = 'HTTPS',
    pathname = `/item/search`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

